package br.com.vendaweb.integracao.entidade;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import java.util.Collection;
import java.util.Iterator;

@Entity
public class Modulo implements Entidade {

	public Modulo(String nome, String descricao) {
		this.nome = nome;
		this.descricao = descricao;
	}
	public Modulo() {
	}

	/**
	 * @uml.property  name="id"
	 */
	@Id
	@SequenceGenerator(name="sq_modulo", sequenceName="sq_modulo", initialValue=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sq_modulo")
	private Long id;

	/**
	 * @uml.property  name="nome"
	 */
	@Column
	private String nome;

	/**
	 * @uml.property  name="descricao"
	 */
	@Column
	private String descricao;

	/**
	 * @uml.property  name="permissao"
	 * @uml.associationEnd  multiplicity="(0 -1)" inverse="modulo:br.com.vendaweb.integracao.entidade.Permissao"
	 */
	@OneToMany(mappedBy="modulo")
	private Collection<Permissao> permissao;

	/**
	 * Getter of the property <tt>descricao</tt>
	 * @return   Returns the descricao.
	 * @uml.property  name="descricao"
	 */
	public String getDescricao() {
		return descricao;
	}

	/**
	 * Getter of the property <tt>id</tt>
	 * @return   Returns the id.
	 * @uml.property  name="id"
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Getter of the property <tt>nome</tt>
	 * @return   Returns the nome.
	 * @uml.property  name="nome"
	 */
	public String getNome() {
		return nome;
	}

	/** 
	 * Getter of the property <tt>permissao</tt>
	 * @return  Returns the permissao.
	 */
	public Collection<Permissao> getPermissao() {
		return permissao;
	}

	/**
	 * Setter of the property <tt>descricao</tt>
	 * @param descricao   The descricao to set.
	 * @uml.property  name="descricao"
	 */
	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	/**
	 * Setter of the property <tt>id</tt>
	 * @param id   The id to set.
	 * @uml.property  name="id"
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Setter of the property <tt>nome</tt>
	 * @param nome   The nome to set.
	 * @uml.property  name="nome"
	 */
	public void setNome(String nome) {
		this.nome = nome;
	}

	/**
	 * Returns an iterator over the elements in this collection. 
	 * @return  an <tt>Iterator</tt> over the elements in this collection
	 * @see java.util.Collection#iterator()
	 */
	public Iterator<Permissao> permissaoIterator() {
		return permissao.iterator();
	}

	/**
	 * Returns <tt>true</tt> if this collection contains no elements.
	 * @return  <tt>true</tt> if this collection contains no elements
	 * @see java.util.Collection#isEmpty()
	 */
	public boolean isPermissaoEmpty() {
		return permissao.isEmpty();
	}

	/**
	 * Returns <tt>true</tt> if this collection contains the specified element. 
	 * @param element  whose presence in this collection is to be tested.
	 * @see java.util.Collection#contains(Object)
	 */
	public boolean containsPermissao(Permissao permissao) {
		return this.permissao.contains(permissao);
	}

	/**
	 * Returns <tt>true</tt> if this collection contains all of the elements in the specified collection.
	 * @param elements  collection to be checked for containment in this collection.
	 * @see java.util.Collection#containsAll(Collection)
	 */
	public boolean containsAllPermissao(
			Collection<? extends Permissao> permissao) {
				return this.permissao.containsAll(permissao);
			}

	/**
	 * Returns the number of elements in this collection.
	 * @return  the number of elements in this collection
	 * @see java.util.Collection#size()
	 */
	public int permissaoSize() {
		return permissao.size();
	}

	/**
	 * Returns all elements of this collection in an array.
	 * @return  an array containing all of the elements in this collection
	 * @see java.util.Collection#toArray()
	 */
	public Permissao[] permissaoToArray() {
		return permissao.toArray(new Permissao[permissao.size()]);
	}

	/**
	 * Returns an array containing all of the elements in this collection;  the runtime type of the returned array is that of the specified array.
	 * @param a  the array into which the elements of this collection are to be stored.
	 * @return  an array containing all of the elements in this collection
	 * @see java.util.Collection#toArray(Object[])
	 */
	public <T extends Permissao> T[] permissaoToArray(T[] permissao) {
		return (T[]) this.permissao.toArray(permissao);
	}

	/**
	 * Ensures that this collection contains the specified element (optional operation). 
	 * @param element  whose presence in this collection is to be ensured.
	 * @see java.util.Collection#add(Object)
	 */
	public boolean addPermissao(Permissao permissao) {
		return this.permissao.add(permissao);
	}

	/** 
	 * Setter of the property <tt>permissao</tt>
	 * @param permissao  The permissao to set.
	 */
	public void setPermissao(Collection<Permissao> permissao) {
		this.permissao = permissao;
	}

	/**
	 * Removes a single instance of the specified element from this collection, if it is present (optional operation).
	 * @param element  to be removed from this collection, if present.
	 * @see java.util.Collection#add(Object)
	 */
	public boolean removePermissao(Permissao permissao) {
		return this.permissao.remove(permissao);
	}

	/**
	 * Removes all of the elements from this collection (optional operation).
	 * @see java.util.Collection#clear()
	 */
	public void clearPermissao() {
		this.permissao.clear();
	}

}
